<?php
Header("content-type: application/x-javascript");
@include('../connect/connect_mysql.php');

function returnimages($page) {
   $query = "Select * from image WHERE page_id = '$page' AND is_deleted = '0'";
   
	if ($page == 5) //event page
	{
		$query_nearest_event = "SELECT * FROM event e WHERE DATE(e.date) <= DATE(NOW()) and is_deleted = 0 ORDER BY DATE(e.date) DESC LIMIT 1";
		mysql_query ("SET NAMES 'utf8'");
		$result = mysql_query($query_nearest_event);
		$row = mysql_fetch_array($result);
		$eventid = $row['event_id'];
		$query = "Select * from image WHERE page_id = '5' AND event_id = '$eventid' AND is_deleted = '0'";
	}
   $pattern="\.(jpg|jpeg|png|gif|bmp)$";
   mysql_query ("SET NAMES 'utf8'");
   $result = mysql_query($query);
    @$num_rows = mysql_num_rows($result);
    if($num_rows == 0) {
       return 0;
    } else {
        $curimage=0;
        while($row = mysql_fetch_array($result))
        {
            $file = $row['path'];
			$width = $row['width'];
			$event_id = $row['event_id'];
			$height = $row['height'];
            $description = $row['comment'];
			$thumb = $row['thumb'];
            echo "		[$curimage, \"$file\", \"$event_id\", \"$description\", \"$width\", \"$height\", \"$thumb\"],\n";
            $curimage++;
        }
        echo "		[\"placeholder\"]\n";
    }
}

//function get_album($photovar, $page)
//{
    $photovar=$_GET['id'];
    $page=$_GET['page'];
    echo "var $photovar={\n";
    //echo "	baseurl: \"http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER['PHP_SELF']) . "/\",\n";
    echo "  baseurl: \"\",\n";
    echo "	images: [\n";
    returnimages($page);
    echo "	],\n";
    echo "	desc: []\n";
    echo "}\n";
//}




?>
